package main

import (
	"github.com/micro/go-micro/v2"
	"log"

	"kop/framework/conf"
	"kop/framework/wrapper"
	"kop/libs/database"
	"kop/modules/configuration/handler"
	"kop/modules/configuration/pb"
	"kop/modules/server/models"
	"kop/pb/service"

	serverH "kop/modules/server/handler"
)

func main() {

	conf.Init()

	var srv = micro.NewService(
		micro.Name("go.micro.srv.configuration"),

		micro.WrapHandler(wrapper.NewLogWrapper),
		micro.AfterStart(
			func() error {
				log.Println("启动配置服务器.")
				return nil
			}),
	)

	// Initialise service
	srv.Init()

	database.DB = database.Open(conf.DataBase.Dsn, conf.DataBase.MaxIdle, conf.DataBase.MaxOpen, conf.DataBase.Log)

	models.AutoMigrate(database.DB)

	// Register handler
	_ = pb.RegisterConfigurationServiceHandler(srv.Server(), new(handler.ConfigurationServiceHandler))
	_ = service.RegisterServerServiceHandler(srv.Server(), new(serverH.ServerServiceHandler))

	if err := srv.Run(); err != nil {
		log.Fatal(err)
	}
}
